//
//  UserViewCell.swift
//  SwiftBase
//
//  Created by 郭艳波 on 2018/3/9.
//  Copyright © 2018年 郭艳波. All rights reserved.
//

import UIKit
import SDWebImage

class UserViewCell: UITableViewCell {
    @IBOutlet weak var avatarImage: UIImageView!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var otherInfoLabel: UILabel!
    @IBOutlet weak var selectIcon: UIImageView!
    
    let femaleText = "Female"
    let maleText = "Male"
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        avatarImage.layer.cornerRadius = avatarImage.frame.width / 2
        avatarImage.layer.masksToBounds = true
    }

    func setData(user: User, selected: Bool) {
        let name = user.name
        let avatar = user.avatar
        let gender = user.gender
        let genderText = gender == 0 ? femaleText : maleText
        
        nameLabel.text = name
        otherInfoLabel.text = "\(genderText) 178cm 24"
        if avatar == "" {
            avatarImage.image = UIImage(named: "icon_default_avatar")
        } else {
            avatarImage.sd_setImage(with: URL(string: CoreConst.IMG_URL_PREFIX + avatar!), completed: nil)
        }
        
        selectIcon.isHidden = !selected
    }
    
}
